<template>
  <div class="app-container">
    <el-form :inline="true" ref="ruleForm" :model="formInline" class="demo-form-inline">
      <el-form-item label="">
        <el-col :span="6">
          <el-form-item prop="dateType">
            <el-select v-model="formInline.dateType" placeholder="请选择时间范围">
              <el-option :label="$t('language.finance.withdrawal.requestTime')" :value="1"></el-option>
              <!--<el-option label="出款时间" :value="2"></el-option>-->
              <el-option :label="$t('language.finance.withdrawal.riskControlSubmissionTime')" :value="3"></el-option>
              <el-option :label="$t('language.finance.withdrawal.dispenseTime')" :value="4"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item prop="time">
            <el-date-picker
              v-model="formInline.time"
              type="datetimerange"
              align="right"
              unlink-panels
              :range-separator="$t('language.finance.recharge.to')"
             :start-placeholder="$t('language.finance.recharge.startDate')"
             :end-placeholder="$t('language.finance.recharge.endDate')"
              :default-time="['00:00:00', '23:59:59']"
              value-format="yyyy-MM-dd HH:mm:ss"
              :picker-options="pickerDayStep">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item :label="$t('language.finance.withdrawal.amount')">
        <el-col :span="11">
          <el-form-item prop="minAmount">
            <el-input @keyup.enter.native="$emit('on-filter',formInline)" type="number" v-model="formInline.minAmount" :placeholder="$t('language.finance.recharge.inputPrompt')"></el-input>
          </el-form-item>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-form-item prop="maxAmount">
            <el-input @keyup.enter.native="$emit('on-filter',formInline)" type="number" v-model="formInline.maxAmount" :placeholder="$t('language.finance.recharge.inputPrompt')"></el-input>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item class="with-pre-select" :label="$t('language.finance.withdrawal.customersWithdrawbank')" prop="cardNo">
        <el-input @keyup.enter.native="$emit('on-filter',formInline)" :placeholder="$t('language.finance.publicFilters.inputCardNum')" v-model="formInline.cardNo" class="input-with-select">
          <el-select v-model="formInline.bankId" slot="prepend">
            <el-option
            :label="$t('language.finance.publicFilters.all')"
            :key="consts.ALL"
            :value="undefined"
          ></el-option>
            <el-option
              v-for="item in $t('language.finance.consts.PAYEE_BANKS')"
              v-if="item.title !== '支付宝二维码' && item.title !== 'Alipay qr code'"
              :label="item.title"
              :key="item.value"
              :value="item.value"
            ></el-option>
          </el-select>
          <!--<el-button slot="append" icon="el-icon-search"></el-button>-->
        </el-input>
      </el-form-item>
      <el-form-item :label="$t('language.finance.recharge.accountType')" prop="userType">
        <el-select v-model="formInline.userType" :placeholder="$t('language.finance.publicFilters.accountType')">
          <el-option
            v-for="item in $t('language.finance.consts.USER_TYPE')"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('language.finance.recharge.operationEnd')" prop="clientType">
        <el-select v-model="formInline.clientType" :placeholder="$t('language.finance.recharge.operationEndPrompt')">
          <el-option
            v-for="item in $t('language.finance.consts.PAYMENT_PLATFORM')"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="tag == 1" :label="$t('language.finance.withdrawal.withdrawalStatus')" prop="status">
        <el-select multiple :collapse-tags="true" v-model="formInline.status" :placeholder="$t('language.finance.publicFilters.selectWithdrawalStatus')" :style="{width: '230px'}">
          <el-option
            v-for="item in $t('language.finance.consts.WITHDRAW_STATUS_ONE')"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="tag == 2" :label="$t('language.finance.withdrawal.withdrawalStatus')" prop="status">
        <el-select multiple :collapse-tags="true" v-model="formInline.status" :placeholder="$t('language.finance.publicFilters.selectWithdrawalStatus')" :style="{width: '230px'}">
          <el-option
            v-for="item in $t('language.finance.consts.WITHDRAW_STATUS_TWO')"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('language.finance.withdrawal.payoutMerchant')" prop="merchant">
        <el-select v-model="formInline.merchant" filterable :placeholder="$t('language.finance.publicFilters.selectMerchant')">
          <el-option
            v-for="item in withdrawShopList"
            :label="item.channelName"
            :key="item.channelId"
            :value="item.channelName"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('language.finance.withdrawal.withdrawalType')" prop="aisleType">
        <el-select v-model="formInline.aisleType" :placeholder="$t('language.finance.publicFilters.selectType')">
         <el-option :label="$t('language.finance.withdrawal.ordinaryWithdrawal')" :value="1"></el-option>
         <el-option :label="$t('language.finance.withdrawal.largeWithdrawals')" :value="2"></el-option>
         <el-option :label="$t('language.finance.withdrawal.agentWithdrawal')" :value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item class="with-pre-select" prop="keywords">
        <el-input @keyup.enter.native="$emit('on-filter',formInline)" :placeholder="$t('language.finance.publicFilters.keyword')"  v-model="formInline.keywords" class="input-with-select">
          <el-select
            @change="searchTypeChange"
            v-model="formInline.searchType" slot="prepend" placeholder="查询范围">
            <el-option :label="$t('language.finance.withdrawal.billNo')" :value="1"></el-option>
            <el-option :label="$t('language.finance.withdrawal.accountName')" :value="2"></el-option>
            <el-option :label="$t('language.finance.withdrawal.name')" :value="4"></el-option>
            <el-option :label="$t('language.finance.recharge.phoneNumber')" :value="5"></el-option>
            <el-option :label="$t('language.finance.withdrawal.thirdPartyWithdrawalBillNo')" :value="6"></el-option>
            <el-option :label="$t('language.finance.withdrawal.payoutMerchantID')" :value="8"></el-option>
            <el-option :label="$t('language.finance.withdrawal.riskHandler')" :value="9"></el-option>
            <el-option :label="$t('language.finance.withdrawal.dispenser')" :value="10"></el-option>
            <el-option :label="$t('language.finance.withdrawal.handler')" :value="11"></el-option>
          </el-select>
          <!--<el-button slot="append" icon="el-icon-search"></el-button>-->
        </el-input>
      </el-form-item>
      <el-form-item label="">
        <el-checkbox-group v-model="formInline.splitType">
          <el-checkbox :label="$t('language.finance.withdrawal.associatedDetachableSingleSearch')" name="splitType"></el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item :label="$t('language.finance.withdrawal.splitState')"  prop="splitStatus">
        <el-select v-model="formInline.splitStatus" :placeholder="$t('language.finance.publicFilters.selectSplitStatus')">
          <el-option
            :label="$t('language.finance.publicFilters.all')"
            :key="consts.ALL"
            :value="-1"
          ></el-option>
          <el-option :label="$t('language.finance.withdrawal.splited')" :value="1"></el-option>
          <el-option :label="$t('language.finance.withdrawal.notSplit')" :value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('language.finance.recharge.level')" prop="userLevel">
        <el-select :collapse-tags="true" v-model="formInline.userLevel" multiple :placeholder="formInline.userLevel?'':$t('language.finance.publicFilters.selectLevel')"  class="with-pre-userLevel">
          <el-option
            v-for="item in levelList"
            :label="item.name"
            :key="item.levelId"
            :value="item.levelId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="$emit('on-filter',formInline)">{{ $t('language.table.search') }}
      <!-- <el-button class="filter-item" type="primary" icon="el-icon-search" @click="con(formInline.time[0])">搜索 -->
      </el-button>
      <el-button @click="selfResetForm('ruleForm')">{{$t('language.table.reset') }}</el-button>
    </el-form>
  </div>

</template>

<script>
import { getUserLevelList } from '@/services/api/userLevel';
import { getUserGroupList } from '@/services/api/userGroup';
import { getWithdrawShopDetail } from '@/services/api/withdraw';
import { form, pickerOption } from '@/build';

export default {
  name: 'auto-filter',
  props: {
    type: {
      type: String,
      default: 'auto', // 分自动和人工
    },
    tag: {
      type: Number,
      default: 1,
    },
  },
  mixins: [form, pickerOption],
  data() {
    return {
      withdrawShopList: [],
      levelList: [],
      groupList: [],
      formInline: {
        dateType: 1,
        searchType: 2,
        keywords: undefined,
        merchant: undefined,
        status: this.tag == 1 ? [7, 3, 6, -3, 0, 10, 11] : [1, 2, 8, -2, 4, 5, 9],
        clientType: undefined,
        userType: undefined,
        bankId: undefined,
        cardNo: undefined,
        maxAmount: undefined,
        minAmount: undefined,
        splitStatus: -1,
        userLevel: [],
        time: [moment().format('YYYY-MM-DD 00:00:00'), moment().format('YYYY-MM-DD 23:59:59')],
        splitType: undefined,
      },

    };
  },
  methods: {
    searchTypeChange() {
      this.formInline.keywords = undefined;
    },
    selfResetForm(formName) {
      this.formInline.splitType = undefined;
      this.resetForm(formName);
      this.$emit('on-filter', this.formInline);
    },
  },
  mounted() {
    if (this.type === 'auto') {
      this.bindGet(getWithdrawShopDetail, 'withdrawShopList', { });
    }
    // this.bindGet(getUserLevelList, 'levelList',{
    //   action: 'getLevel'
    // });
    // this.doAction({type:'get',action:'getLevel'});
    this.bindGet(getUserLevelList, 'levelList', { });
    // this.bindGet(getUserGroupList, 'groupList', { });//todo 1-获取群组
    this.getAll();
  },
};
</script>

<style lang="scss" scoped>
  .with-pre-select {
    .el-input-group__prepend {
      .el-select {
        width: 120px;
      }
    }
  }
  /deep/ .with-pre-userLevel .el-tag{
    max-width: 105px!important;
  }
  .money-range {
    .el-input {
      width: 100px;
    }
  }
</style>
